﻿using DryIoc;
using Prism.Commands;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ModuleA.ViewModels
{
    public class UCDialogAViewModel : IDialogAware
    {
        public string Title { get; set; } = "这是我测试的对话框标题";

        public DelegateCommand ConfirmCmd { get; set; }

        private void Confirm()
        {
            if (RequestClose != null)
            {
                DialogParameters paras = new DialogParameters();
                paras.Add("MsgA", "这是我测试的对话框返回值");
                RequestClose(new DialogResult(ButtonResult.Yes,paras));
            }
        }

        public DelegateCommand CancelCmd { get; set; }

        private void Cancel()
        {
            RequestClose?.Invoke(new DialogResult(ButtonResult.No));
        }

        public event Action<IDialogResult> RequestClose;

        public UCDialogAViewModel()
        {
            CancelCmd = new DelegateCommand(Cancel);
            ConfirmCmd = new DelegateCommand(Confirm);
        }

        /// <summary>
        /// 关闭对话框
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
            //if (RequestClose != null)
            //    RequestClose(new DialogResult(ButtonResult.No));
            RequestClose?.Invoke(new DialogResult(ButtonResult.No));
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            Title = parameters.GetValue<string>("Title");
            string p1 = parameters.GetValue<string>("p1");
            string p2 = parameters.GetValue<string>("p2");
        }
    }
}
